#=
This file is part of the replication code for: Hasenzagl, T., Pellegrino, F., Reichlin, L., & Ricco, G. (2020). A Model of the Fed's View on Inflation.
Please cite the paper if you are using any part of the code for academic work (including, but not limited to, conference and peer-reviewed papers).
=#

# ----------------------------------------------------------------------------------------------------------------------
# Initial settings
# ----------------------------------------------------------------------------------------------------------------------

using Distributed;
include("read_data.jl");
include("tc_mwg.jl");
include("tc_mwg_global.jl");
@everywhere include("MetropolisWithinGibbs.jl")
@everywhere using DataFrames, Dates, FileIO, JLD, LinearAlgebra, Random, Statistics, XLSX;
@everywhere using Main.MetropolisWithinGibbs;

end_presample_vec = [31, 12, 1998]; # End presample, day/month/year [it is used when run_type is 2 or 3]
h = 8; # forecast horizon [it is used when run_type is 1 or 3]


# ----------------------------------------------------------------------------------------------------------------------
# Metropolis-Within-Gibbs settings
# ----------------------------------------------------------------------------------------------------------------------
nDraws    = [60000; 40000]; # [number of draws in initialization; number of draws in execusion]
burnin    = nDraws .- 20000; # number of draws in the burn-in stage
mwg_const = [0.025; 0.25]; # Initial constant. mwg_const might be adjusted to get an acceptance rate between 25% and 35%

#=
------------------------------------------------------------------------------------------------------------------------
Run type
------------------------------------------------------------------------------------------------------------------------
1. Single iteration: it executes the code using the most updated datapoints
2. Conditional forecast (you need to run option 1 first)
3. Out-of-sample: out-of-sample exercise, forecasting period starts after end_presample_vec
------------------------------------------------------------------------------------------------------------------------
Model type
------------------------------------------------------------------------------------------------------------------------
1. Main 8-variable model 
2. Model with global data 
-----------------------------------------------------------------------------------------------------------------------
=#

run_type = 1;
model_type = 1;

if run_type == 1
	res_name = "iis"
elseif run_type == 2
	res_name = "cond"
elseif run_type == 3
	res_name = "oos"
end

if model_type == 1 
	data_path = "inflation.xlsx"; 
elseif model_type == 2
	data_path = "inflation_global.xlsx"; 
end	

# Name for the in-sample results (used only in the conditional forecast mode)
res_name_iis = "iis";

#=
The variable `cond` is used only when run_type == 2.

It needs to be defined with a structure analogous to:

cond = [Dict("EMPL" => [51.30], "U" => [14.70], "OIL" => [16.61], "UOM" => [2.10]),
        Dict("EMPL" => [55.00], "U" => [10.00], "OIL" => [20.00]),
        Dict("U" => [15.00]),
        Dict("U" => [10.00]),
        Dict("U" => [15.00, 10.00])];
=#
cond = [];

# Load data
data, date, nM, nQ, MNEMONIC = read_data(data_path);

# ----------------------------------------------------------------------------------------------------------------------
# Execution
# ----------------------------------------------------------------------------------------------------------------------

# Fix random seed
Random.seed!(2);

# Run code
include("tc_main.jl");
